package com.hkd.product_service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkd.common.api.ApiResponse;
import com.hkd.product_service.api.ProductCategoryService;
import com.hkd.product_service.api.dto.InsertProductCategoryDTO;
import com.hkd.product_service.mapper.ProductCategoryMapper;
import com.hkd.product_service.api.entity.ProductCategory;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HKD
 * @date 2022/9/17 21:35
 */
@RestController
public class ProductCategoryServiceImpl extends ServiceImpl<ProductCategoryMapper, ProductCategory> implements ProductCategoryService {

    @Override
    public ApiResponse insertProductCategory(String curUserId, List<InsertProductCategoryDTO> param) {
        List<ProductCategory> productCategories = BeanUtil.copyToList(param, ProductCategory.class);
        productCategories.forEach(item->{
            item.setCreateId(curUserId);
            item.setUpdateId(curUserId);
        });
        this.saveBatch(productCategories);
        return ApiResponse.ok();
    }
}
